<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/vue.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        .menu {
            display: flex;
        }

        .menu .item {
            flex: 1;
            text-align: center;
            line-height: 40px;
            background-color: black;
            color: white;
        }

        .menu .active {
            background-color: red;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="menu">
            <div v-for="item in  menu" class="item" :class="{active:item.checked}" @click="change(item)">
                {{item.msg}}
            </div>
        </div>
    </div>
</body>
<script>
    new Vue({
        el: "#app",
        data: {

            menu: [{ id: 1, msg: "菜单一", checked: true }, { id: 2, msg: "菜单二", checked: false }, { id: 3, msg: "菜单三", checked: false }, { id: 4, msg: "菜单四", checked: false }]
        },
        methods: {
            change(item) {
                this.menu.forEach(info => {
                    if (info == item) {
                        info.checked = true;
                    } else {
                        info.checked = false;
                    }
                })

            }

        }
    })


</script>

</html>